import axios from "axios"
import Nproress from "nprogress"
import "nprogress/nprogress.css"

const mockAjax = axios.create({
  baseURL: "/mock",
  timeout: 1000,
})

mockAjax.interceptors.request.use((config) => {
  Nproress.start()
  return config
})

mockAjax.interceptors.response.use(
  (response) => {
    Nproress.done()
    return response.data
  },
  (error) => {
    Nproress.done()
    return Promise.reject(new Error(error.message))
  }
)

export default mockAjax
